home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / rmail / rmailedit.el.z / rmailedit.el
Encoding:
Text File  |  1998-05-21  |  4.0 KB  |  116 lines

  1. ;;; rmailedit.el --- "RMAIL edit mode"  Edit the current message.
  2.  
  3. ;; Copyright (C) 1985 Free Software Foundation, Inc.
  4.  
  5. ;; Maintainer: FSF
  6. ;; Keywords: mail
  7.  
  8. ;; This file is part of XEmacs.
  9.  
  10. ;; XEmacs is free software; you can redistribute it and/or modify it
  11. ;; under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14.  
  15. ;; XEmacs is distributed in the hope that it will be useful, but
  16. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18. ;; General Public License for more details.
  19.  
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with XEmacs; see the file COPYING.  If not, write to the 
  22. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  23. ;; Boston, MA 02111-1307, USA.
  24.  
  25. ;;; Code:
  26.  
  27. (require 'rmail)
  28.  
  29. (defvar rmail-edit-map nil)
  30. (if rmail-edit-map
  31.     nil
  32.   (setq rmail-edit-map (make-sparse-keymap))
  33.   (set-keymap-parent rmail-edit-map text-mode-map)
  34.   (set-keymap-name rmail-edit-map 'rmail-edit-map)
  35.   (define-key rmail-edit-map "\C-c\C-c" 'rmail-cease-edit)
  36.   (define-key rmail-edit-map "\C-c\C-]" 'rmail-abort-edit))
  37.  
  38. ;; Rmail Edit mode is suitable only for specially formatted data.
  39. (put 'rmail-edit-mode 'mode-class 'special)
  40.  
  41. (defun rmail-edit-mode ()
  42.   "Major mode for editing the contents of an RMAIL message.
  43. The editing commands are the same as in Text mode, together with two commands
  44. to return to regular RMAIL:
  45.   *  rmail-abort-edit cancels the changes
  46.      you have made and returns to RMAIL
  47.   *  rmail-cease-edit makes them permanent.
  48. \\{rmail-edit-map}"
  49.   (use-local-map rmail-edit-map)
  50.   (setq major-mode 'rmail-edit-mode)
  51.   (setq mode-name "RMAIL Edit")
  52.   (if (boundp 'mode-line-modified)
  53.       (setq mode-line-modified (default-value 'mode-line-modified))
  54.     (setq mode-line-format (default-value 'mode-line-format)))
  55.   (run-hooks 'text-mode-hook 'rmail-edit-mode-hook))
  56.  
  57. (defvar rmail-old-text) ;jwz
  58. (defun rmail-edit-current-message ()
  59.   "Edit the contents of this message."
  60.   (interactive)
  61.   (rmail-edit-mode)
  62.   (make-local-variable 'rmail-old-text)
  63.   (setq rmail-old-text (buffer-substring (point-min) (point-max)))
  64.   (setq buffer-read-only nil)
  65.   (set-buffer-modified-p (buffer-modified-p))
  66.   ;; Make mode line update.
  67.   (if (and (eq (key-binding "\C-c\C-c") 'rmail-cease-edit)
  68.        (eq (key-binding "\C-c\C-]") 'rmail-abort-edit))
  69.       (message "Editing: Type C-c C-c to return to Rmail, C-c C-] to abort")
  70.     (message (substitute-command-keys
  71.            "Editing: Type \\[rmail-cease-edit] to return to Rmail, \\[rmail-abort-edit] to abort"))))
  72.  
  73. (defun rmail-cease-edit ()
  74.   "Finish editing message; switch back to Rmail proper."
  75.   (interactive)
  76.   ;; Make sure buffer ends with a newline.
  77.   (save-excursion
  78.     (goto-char (point-max))
  79.     (if (/= (preceding-char) ?\n)
  80.     (insert "\n"))
  81.     ;; Adjust the marker that points to the end of this message.
  82.     (set-marker (aref rmail-message-vector (1+ rmail-current-message))
  83.         (point)))
  84.   (let ((old rmail-old-text))
  85.     ;; Update the mode line.
  86.     (set-buffer-modified-p (buffer-modified-p))
  87.     (rmail-mode-1)
  88.     (if (and (= (length old) (- (point-max) (point-min)))
  89.          (string= old (buffer-substring (point-min) (point-max))))
  90.     ()
  91.       (setq old nil)
  92.       (rmail-set-attribute "edited" t)
  93.       (if (boundp 'rmail-summary-vector)
  94.       (progn
  95.         (aset rmail-summary-vector (1- rmail-current-message) nil)
  96.         (save-excursion
  97.           (rmail-widen-to-current-msgbeg
  98.             (function (lambda ()
  99.                 (forward-line 2)
  100.                 (if (looking-at "Summary-line: ")
  101.                 (let ((buffer-read-only nil))
  102.                   (delete-region (point)
  103.                          (progn (forward-line 1)
  104.                             (point))))))))
  105.           (rmail-show-message))))))
  106.   (setq buffer-read-only t))
  107.  
  108. (defun rmail-abort-edit ()
  109.   "Abort edit of current message; restore original contents."
  110.   (interactive)
  111.   (delete-region (point-min) (point-max))
  112.   (insert rmail-old-text)
  113.   (rmail-cease-edit))
  114.  
  115. ;;; rmailedit.el ends here
  116.